package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.TravelCommend;
import cn.wolfcode.luowowo.article.mapper.TravelCommendMapper;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import cn.wolfcode.luowowo.common.query.TravelQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService{
    @Autowired
    private TravelCommendMapper travelCommendMapper;

    public PageInfo query(TravelQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelCommend> list = travelCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void deleteById(Long id) {
        travelCommendMapper.deleteByPrimaryKey(id);
    }

    public void saveOrUpdate(TravelCommend travelCommend) {
        if(travelCommend.getId() == null){
            //新增操作
            travelCommendMapper.insert(travelCommend);
        }else{
            //更新操作
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        }
    }

    public List<TravelCommend> selectAllCommends() {

        return travelCommendMapper.selectAll();
    }

    public List<TravelCommend> selectCommendsTop5() {

        return travelCommendMapper.selectCommendsTop5();
    }
}
